using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Data;
using System.Net;

namespace NET.Library.XML
{
    /// <summary>
    /// 
    /// </summary>
    public class RSS
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="RSSFeedURL"></param>
        /// <returns></returns>
        public static XmlDocument GetXMLFeed(string RSSFeedURL)
        {
            //Get a web reponse from the RSS site
            WebRequest request = WebRequest.Create(RSSFeedURL);
            WebResponse response = request.GetResponse();

            //Load response into an XML document
            XmlDocument doc = new XmlDocument();
            doc.Load (response.GetResponseStream());
            return doc;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="RSSFeedURL"></param>
        /// <returns></returns>
        public static DataSet GetDataSetFeed(string RSSFeedURL)
        {
            //Get a web reponse from the RSS site
            WebRequest request = WebRequest.Create(RSSFeedURL);
            WebResponse response = request.GetResponse();

            //Load response into an XML document
            //XmlDocument doc = new XmlDocument();
            //doc.Load(response.GetResponseStream());

            //Load response into a DataSet
            DataSet ds = new DataSet();
            ds.ReadXml(response.GetResponseStream(), XmlReadMode.Auto);


            return ds;
        }
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="RSSFeedURL"></param>
        ///// <returns></returns>
        //public static DataSet GetDataSetFeed(string RSSFeedURL)
        //{//requires an xmlschema to be used with a dataset. Not sure if this will work this way, looks way too easy.
        //    WebRequest request = WebRequest.Create(RSSFeedURL);
        //    WebResponse response = request.GetResponse();

        //    //Load response into an XML document
        //    XmlDataDocument doc = new XmlDataDocument();
        //    doc.Load(response.GetResponseStream());

        //    //DataSet ds = new DataSet();
        //    //DataTable dt = doc. //new DataTable();

        //    //ds.Tables.Add(dt);
        //    return doc.DataSet;
        //}

        //public static DataSet GetDataSetFeed(string RSSFeedURL)
        //{//requires an xmlschema to be used with a dataset
        //    WebRequest request = WebRequest.Create(RSSFeedURL);
        //    WebResponse response = request.GetResponse();

        //    //Load response into an XML document
        //    XmlDocument doc = new XmlDocument();
        //    doc.Load(response.GetResponseStream());

        //    DataSet ds = new DataSet();
        //    DataTable dt = new DataTable();
        //    ds.Tables.Add(dt);

        //    XmlNodeList items = doc.SelectNodes("rss/channel/item");

        //    dt.Columns.Add("ID"); //look up specifying the data tyep as well when creating a column
        //    dt.Columns.Add("Title");
        //    dt.Columns.Add("Description");
        //    dt.Columns.Add("Link");

        //    foreach (XmlNode node in items)
        //    {
        //        //DataRow dr = new DataRow();

                
        //    }
        //    //DataTable dt = doc. //new DataTable();

        //    //ds.Tables.Add(dt);
        //    //return doc.DataSet;
        //}
    }
}
